﻿




Public Class MainForm
    Dim admin As Boolean = False

    Dim vieneDeVentas = False
    Dim vieneDeClientes = False

    Dim prendas() As String = {"Vestido", "Top", "Falda", "Pantalon", "Short", "Abrigo", "Pijama"} ', "Cinturon", "Collar", "Guantes", "Sombrero", "Cartera", "Gafas", "Zapatos", "Botas", "Sandalias", "Bolso"}
    Dim tipos() As String = {"de Piel", "de Lana", "de Lino", "de Pequeño Tamaño", "de Mediano Tamaño", "de Gran Tamaño", "Chic", "Trendy", "Sexy", "de Cocktail", "Etiqueta negra", "Vacacional", "de Cena", "de Tarde"}
    Dim nombres() As String = {"Pumpkin", "Ghost", "Cloud", "Vintage", "Cashimere", "Twit", "Tópico", "Military", "Garibaldi", "Eisenhower", "Cardigan", "Mao", "Nehru", "Bloomer", "Wellington", "Stetson", "Mackintosh", "Hawaii", "Damascus", "Polonaise", "Balaclava", "Shirtwaist", "Sheath", "Ensueño", "Gorgeous", "Luxurious", "Elegant", "Marvellous", "Exquisite", "Inspiring", "Fabolous", "Strinking", "Glamorous", "Fascinating", "Seductive", "Splendid", "Fantastic", "Prominent", "Fancy", "Fairytale", "Superior", "Red Carpet", "Imperial"}
    Dim temporadas() As String = {"Verano", "Otoño", "Invierno", "Primavera"}
    Dim disenadores() As String = {"Zunzu", "Dabas", "DelaPeña", "Ayralexa", "Lezkus", "Nando"}
    Dim zonas() As String = {"Escaparate", "Pasillo principal", "Trastienda", "Pasillo secundario"}

    Dim personas() As Image = {My.Resources.per1, My.Resources.per2, My.Resources.per3, My.Resources.per4, My.Resources.per5, My.Resources.per6, My.Resources.per7, My.Resources.per8, My.Resources.per9, My.Resources.per10, My.Resources.per11, My.Resources.per12, My.Resources.per13, My.Resources.per14, My.Resources.per15, My.Resources.per16, My.Resources.per17, My.Resources.per18, My.Resources.per19, My.Resources.per20}

    Dim vestidos() As Image = {My.Resources.ves1, My.Resources.ves2, My.Resources.ves3, My.Resources.ves4, My.Resources.ves5, My.Resources.ves6, My.Resources.ves7, My.Resources.ves8, My.Resources.ves9, My.Resources.ves10, My.Resources.ves11, My.Resources.ves12, My.Resources.ves13, My.Resources.ves14, My.Resources.ves15, My.Resources.ves16, My.Resources.ves17, My.Resources.ves18, My.Resources.ves19, My.Resources.ves20}
    Dim tops() As Image = {My.Resources.top1, My.Resources.top2, My.Resources.top3, My.Resources.top4, My.Resources.top5, My.Resources.top6, My.Resources.top7, My.Resources.top8, My.Resources.top9, My.Resources.top10, My.Resources.top11, My.Resources.top12, My.Resources.top13, My.Resources.top14, My.Resources.top15, My.Resources.top16, My.Resources.top17, My.Resources.top18, My.Resources.top19, My.Resources.top20}
    Dim faldas() As Image = {My.Resources.fal1, My.Resources.fal2, My.Resources.fal3, My.Resources.fal4, My.Resources.fal5, My.Resources.fal6, My.Resources.fal7, My.Resources.fal8, My.Resources.fal9, My.Resources.fal10} ', My.Resources.fal11, My.Resources.fal12, My.Resources.fal13, My.Resources.fal14, My.Resources.fal15, My.Resources.fal16, My.Resources.fal17, My.Resources.fal18, My.Resources.fal19, My.Resources.fal20}
    Dim pantalones() As Image = {My.Resources.pan1, My.Resources.pan2, My.Resources.pan3, My.Resources.pan4, My.Resources.pan5, My.Resources.pan6, My.Resources.pan7, My.Resources.pan8, My.Resources.pan9, My.Resources.pan10} ', My.Resources.pan11, My.Resources.pan12, My.Resources.pan13, My.Resources.pan14, My.Resources.pan15, My.Resources.pan16, My.Resources.pan17, My.Resources.pan18, My.Resources.pan19, My.Resources.pan20}
    Dim shorts() As Image = {My.Resources.sho1, My.Resources.sho2, My.Resources.sho3, My.Resources.sho4, My.Resources.sho5, My.Resources.sho6, My.Resources.sho7, My.Resources.sho8, My.Resources.sho9, My.Resources.sho10} ', My.Resources.sho11, My.Resources.sho12, My.Resources.sho13, My.Resources.sho14, My.Resources.sho15, My.Resources.sho16, My.Resources.sho17, My.Resources.sho18, My.Resources.sho19, My.Resources.sho20}
    Dim abrigos() As Image = {My.Resources.abr1, My.Resources.abr2, My.Resources.abr3, My.Resources.abr4, My.Resources.abr5, My.Resources.abr6, My.Resources.abr7, My.Resources.abr8, My.Resources.abr9, My.Resources.abr10} ', My.Resources.abr11, My.Resources.abr12, My.Resources.abr13, My.Resources.abr14, My.Resources.abr15, My.Resources.abr16, My.Resources.abr17, My.Resources.abr18, My.Resources.abr19, My.Resources.abr20}
    Dim pijamas() As Image = {My.Resources.pij1, My.Resources.pij2, My.Resources.pij3, My.Resources.pij4, My.Resources.pij5, My.Resources.pij6, My.Resources.pij7, My.Resources.pij8, My.Resources.pij9, My.Resources.pij10}
    Dim imgprendas()() As Image = {vestidos, tops, faldas, pantalones, shorts, abrigos, pijamas}

    Dim escapartes() As Image = {My.Resources.FP, My.Resources.FNP}
    Dim interiores() As Image = {My.Resources.IC, My.Resources.ID, My.Resources.IH, My.Resources.IV}
  
    Dim separador As Char = "-"

    Private Function purgeLists()

        Dim countitems As Integer = ListBoxItems.Items.Count - 2
        For i = 0 To countitems
vueltaevitarcrash:
            For j = i + 1 To countitems
                If ListBoxItems.Items(i).ToString.Contains(ListBoxItems.Items(j).ToString) Then
                    ListBoxItems.Items.RemoveAt(j)
                    countitems -= 1
                    GoTo vueltaevitarcrash
                End If
            Next
        Next

        countitems = ListBoxTipos.Items.Count - 2
        For i = 0 To countitems
            For j = i + 1 To countitems
                If ListBoxTipos.Items(i).ToString.Contains(ListBoxTipos.Items(j).ToString) Then
                    ListBoxTipos.Items.RemoveAt(j)
                    countitems -= 1
                End If
            Next
        Next
    End Function
    Private Function surroundByChar(ByVal entrada As String)
        Return ("'" + entrada + "'")
    End Function
    Private Function rndString(ByRef s As String())
        Return s(nextRandom(s.Length - 1, 0))
    End Function
    Private Function rndImage(ByRef i As Image())
        Return i(nextRandom(i.Length - 1, 0))
    End Function
    Public Function addRandomItems(ByVal numeroTipos As Integer, ByVal numeroItems As Integer)
        ListBoxTipos.Items.Clear()
        ListBoxItems.Items.Clear()
        For i = 0 To numeroTipos
            ListBoxTipos.Items.Add(prendas(nextRandom(prendas.Length - 1, 0)) + " " + tipos(nextRandom(tipos.Length - 1, 0)))
            For j = 0 To nextRandom(numeroItems, 0)
                ListBoxItems.Items.Add(ListBoxTipos.Items(i).ToString + " " + surroundByChar(nombres(nextRandom(nombres.Length - 1, 0))))
            Next
        Next
        purgeLists()
    End Function





    Private Sub ButtonBuscarStock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBuscarStock.Click
        If (Not CheckBox1.Checked And Not CheckBox2.Checked) Then
            MsgBox("Seleccione un ámbito de búsqueda", MsgBoxStyle.Information)
            Return
        End If


        ProgressBar1.Value = 0
        ListBoxTipos.Items.Clear()
        ListBoxItems.Items.Clear()
        Dim encontrado As Boolean = False
        For i = 0 To prendas.Length - 1
            If (prendas(i).ToLower.Contains(TextBoxStockInput.Text.ToLower)) Then
                encontrado = True
                For j = 1 To nextRandom((tipos.Length - 1) * 3 / 2, 1)
                    Dim tipo As String = tipos(nextRandom(tipos.Length - 1, 0))
                    Dim encontrado2 As Boolean = False
                    For k = 0 To ListBoxTipos.Items.Count() - 1
                        If (ListBoxTipos.Items(k).ToString.Contains((prendas(i) + " " + tipo))) Then
                            encontrado2 = True
                        End If
                    Next
                    If (Not encontrado2) Then
                        ListBoxTipos.Items.Add(prendas(i) + " " + tipo)
                    End If
                Next
            End If
        Next
        ProgressBar1.Value = 100

        If (Not encontrado) Then
            MsgBox("No se encontraron coincidencias", MsgBoxStyle.Information)
        End If



        'ListBoxItems.Items.Add(ListBoxTipos.SelectedItem.ToString)
    End Sub
    Private Sub ListBoxTipos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxTipos.Click
        Try
            ListBoxItems.Items.Clear()
            For j = 1 To nextRandom((nombres.Length - 1) * 3 / 2, 1)
                Dim nombre As String = nombres(nextRandom(nombres.Length - 1, 0))
                Dim encontrado2 As Boolean = False
                For k = 0 To ListBoxItems.Items.Count() - 1
                    If (ListBoxItems.Items(k).ToString.Contains(ListBoxTipos.SelectedItem.ToString() + " " + surroundByChar(nombre))) Then
                        encontrado2 = True
                    End If
                Next
                If (Not encontrado2) Then
                    ListBoxItems.Items.Add(ListBoxTipos.SelectedItem.ToString() + " " + surroundByChar(nombre))
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub
    Private Sub ListBoxItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxItems.Click
        Try
            Dim a As String = (ListBoxItems.SelectedItem.ToString)
            For i = 0 To prendas.Length - 1
                If (a.Contains(prendas(i))) Then
                    PictureBoxItem.Image = imgprendas(i)(nextRandom(imgprendas(i).Length - 1, 0))
                    currentDisplayImage = PictureBoxItem.Image
                End If
            Next
            TextBoxStockDetalles.Text = ListBoxItems.SelectedItem.ToString + vbNewLine + vbNewLine _
             + "Año: " + nextRandom(2012, 1990).ToString + vbNewLine _
             + "Temporada: " + temporadas(nextRandom(temporadas.Length - 1, 0)) + vbNewLine _
             + "Diseñador: " + disenadores(nextRandom(disenadores.Length - 1, 0)) + vbNewLine _
             + vbNewLine _
             + "Precio: " + nextRandom(2000, 100).ToString + "€" + vbNewLine _
             + "Stock: " + nextRandom(50, 0).ToString + " uds" + vbNewLine _
             + "Talla(s): " + nextRandom(35, 30).ToString + "-" + nextRandom(45, 36).ToString + vbNewLine _
             + "Zona: " + rndString(zonas) + vbNewLine _
             + vbNewLine _
             '+ "Es súper cómodo," + vbNewLine + _
            '"Nos comenta María Luisa"

        Catch ex As Exception

        End Try
    End Sub










    Private Sub PictureBoxItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxItem.Click
        ImageForm.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEncargar.Click
        InquiryForm.Show()
    End Sub

    Private Sub ButtonEditarDetalles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEditarProducto.Click
        If (TextBoxStockDetalles.ReadOnly = True) Then
            If (Not TextBoxStockDetalles.Text = "") Then
                TextBoxStockDetalles.ReadOnly = False
                ButtonEditarProducto.Text = "Guardar cambios"
            Else
                MsgBox("No hay producto seleccionado", MsgBoxStyle.Information)
            End If

        Else
            If (Not TextBoxStockDetalles.Text = "") Then
                TextBoxStockDetalles.ReadOnly = True
                ButtonEditarProducto.Text = "Editar producto"
                MsgBox("Edición correcta", MsgBoxStyle.Information)
            Else
                MsgBox("Introduzca los detalles", MsgBoxStyle.Critical)
            End If
        End If
    End Sub


    Private Sub ButtonBusquedaAvanzadaItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBusquedaAvanzadaItems.Click
        BusquedaAvanzada.Show()
    End Sub

    Dim puestos() As String = {"Ventas    ", "Sastre    ", "Reposición", "Contable  ", "Dirección ", "Gerencia  "}
    Dim departamentos() As String = {"Tienda ", "Almacén", "General"}
    Dim lugares() As String = {"Castellana", "Plaza Mayor", "Serrano", "Valencia", "Sevilla", "Barcelona"}
    Dim letras() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}


    Private Function randomizeEmployees()
        For i = 0 To letras.Length - 1
            For j = 0 To letras.Length - 1
                For k = 0 To letras.Length - 1
                    If nextRandom(100, 0) = 0 Then
                        ListBoxEmployeesTotal.Items.Add((letras(i) + "." + letras(j) + "." + letras(k) + "." + " -" _
                        + puestos(nextRandom(puestos.Length - 1, 0)) + " -" _
                        + departamentos(nextRandom(departamentos.Length - 1, 0)) + " -" _
                        + lugares(nextRandom(lugares.Length - 1, 0))))
                        'ListBoxEmployees.Items.Add(ListBoxEmployeesTotal.Items(ListBoxEmployeesTotal.Items.Count - 1))
                    End If
                Next
            Next
        Next
        ListBoxEmployees.Items.AddRange(ListBoxEmployeesTotal.Items)
    End Function
    Private Function randomizeClients()
        For i = 0 To letras.Length - 1
            For j = 0 To letras.Length - 1
                For k = 0 To letras.Length - 1
                    If nextRandom(50, 0) = 0 Then
                        ListBoxClientesIncial.Items.Add(letras(i) + "." + letras(j) + "." + letras(k) + ".")
                    End If
                Next
            Next
        Next
        ListBoxClientes.Items.AddRange(ListBoxClientesIncial.Items)
    End Function
    Private Function randomizeSales()
        For i = 2012 To 1970 Step -1
            For j = 12 To 1 Step -1
                For k = 31 To 1 Step -1
                    Dim cerodia As String = ""
                    If (k < 10) Then
                        cerodia = "0"
                    End If
                    Dim ceromes As String = ""
                    If (j < 10) Then
                        ceromes = "0"
                    End If

                    If (nextRandom(5, 0) = 0) Then

                        ListBoxVentasIniciales.Items.Add(i.ToString + "/" + ceromes + j.ToString + "/" + cerodia + k.ToString + " - " _
                        + ListBoxClientesIncial.Items(nextRandom(ListBoxClientesIncial.Items.Count - 1, 0)).ToString + " - " _
                        + ListBoxEmployeesTotal.Items(nextRandom(ListBoxEmployeesTotal.Items.Count - 1, 0)).ToString.Split("-")(0).Trim(" ") + " - " _
                        + rndString(prendas) + " " + rndString(tipos) + " " + surroundByChar(rndString(nombres)))

                    End If
                Next
            Next
        Next
        ListBoxVentas.Items.AddRange(ListBoxVentasIniciales.Items)
    End Function
    Private Function randomizeShop()
        T11.Image = rndImage(interiores)
        T12.Image = rndImage(interiores)
        T13.Image = rndImage(interiores)
        T14.Image = rndImage(interiores)
        T15.Image = rndImage(interiores)
        T21.Image = rndImage(interiores)
        T22.Image = rndImage(interiores)
        T23.Image = rndImage(interiores)
        T24.Image = rndImage(interiores)
        T25.Image = rndImage(interiores)
        T31.Image = rndImage(interiores)
        T32.Image = rndImage(interiores)
        T33.Image = rndImage(interiores)
        T34.Image = rndImage(interiores)
        T35.Image = rndImage(interiores)
        T41.Image = rndImage(interiores)
        T42.Image = rndImage(interiores)
        T43.Image = rndImage(interiores)
        T44.Image = rndImage(interiores)
        T45.Image = rndImage(interiores)
        E1.Image = rndImage(escapartes)
        E2.Image = rndImage(escapartes)
        E3.Image = rndImage(escapartes)
        E4.Image = rndImage(escapartes)
        E5.Image = rndImage(escapartes)
    End Function


    Private Sub TextBusquedaEmpleadosChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxTienda.TextChanged, TextBoxDepartamento.TextChanged, TextBoxNombre.TextChanged, TextBoxPuesto.TextChanged


        ListBoxEmployees.Items.Clear()
        ListBoxEmployees.Items.AddRange(ListBoxEmployeesTotal.Items)
        Dim countEmpleados As Integer = ListBoxEmployees.Items.Count() - 1

        For i = 0 To countEmpleados
            'Try
            Dim piezas() As String = ListBoxEmployees.Items(i).ToString.Split(separador)

            If ((Not piezas(0).ToLower.Contains(TextBoxNombre.Text.ToLower())) Or (Not piezas(1).ToLower.Contains(TextBoxPuesto.Text.ToLower())) Or (Not piezas(2).ToLower.Contains(TextBoxDepartamento.Text.ToLower())) Or (Not piezas(3).ToLower.Contains(TextBoxTienda.Text.ToLower()))) Then
                ListBoxEmployees.Items.RemoveAt(i)
                countEmpleados -= 1
                i -= 1
            End If
            If (i = countEmpleados) Then
                Exit Sub
            End If
            'Catch ex As Exception

            ' End Try
        Next
    End Sub

    Private Sub ListBoxEmployees_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxEmployees.Click
        Try
            Dim piezas() As String = ListBoxEmployees.SelectedItem.ToString.Split(separador)
            piezas(0) = piezas(0).Trim(" ")
            piezas(1) = piezas(1).Trim(" ")
            piezas(2) = piezas(2).Trim(" ")
            piezas(3) = piezas(3).Trim(" ")
            TextBoxEmNombre.Text = piezas(0)
            TextBoxEmPuesto.Text = piezas(1)
            TextBoxEmDepartamento.Text = piezas(2)
            TextBoxEmTienda.Text = piezas(3)
            TextBoxEmAntiguedad.Text = nextRandom(10, 0).ToString + " años"
            TextBoxEmEdad.Text = nextRandom(60, 25).ToString + " años"
            TextBoxEmSueldo.Text = nextRandom(10000, 1500).ToString + "€"
            PictureBoxEmpleado.Image = personas(nextRandom(personas.Length - 1, 0))

            TextBoxEmDetalle.Text = piezas(0) + " ha sido de gran ayuda a la empresa, trabajando de " + piezas(1) + _
            " en el departamento " + piezas(2) + " de la tienda " + piezas(3)
        Catch ex As Exception
        End Try





    End Sub




    Private Sub ListBoxClientes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBoxClientes.Click
        Try

            TextBoxDesdeCliente.Text = nextRandom(2012, 1980)
            TextBoxEdadCliente.Text = nextRandom(80, 25)
            If ((Not vieneDeVentas) And (Not vieneDeClientes)) Then
                Dim piezas() As String = ListBoxClientes.SelectedItem.ToString.Split(separador)
                TextBoxNombreCliente.Text = ListBoxClientes.SelectedItem.ToString
            ElseIf (vieneDeVentas) Then
                TextBoxNombreCliente.Text = ListBoxVentas.SelectedItem.ToString.Split(separador)(1)
            Else
                TextBoxNombreCliente.Text = ListBoxGestionClientes.SelectedItem.ToString
            End If


            TextBoxTiendaCliente.Text = lugares(nextRandom(lugares.Length - 1, 0))
            TextBoxClienteEmail.Text = TextBoxNombreCliente.Text.Trim(" ") + "@mail.com"
            TextBoxClienteTelefono.Text = nextRandom(699999999, 600000000)
            TextBoxTallaCliente.Text = nextRandom(35, 50)
            ListBoxComprasCliente.Items.Clear()
            For j = 0 To nextRandom(40, 0)
                ListBoxComprasCliente.Items.Add(prendas(nextRandom(prendas.Length - 1, 0)) + " " + tipos(nextRandom(tipos.Length - 1, 0)) + " " + surroundByChar(nombres(nextRandom(nombres.Length - 1, 0))))
            Next
            Dim a As Integer
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox1.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox2.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox3.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox4.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox5.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox6.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox7.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))
            a = nextRandom(imgprendas.Length - 1, 0)
            PictureBox8.Image = imgprendas(a)(nextRandom(imgprendas(a).Length - 1, 0))

        Catch ex As Exception
        End Try

    End Sub

    Private Sub TextBoxBuscarCli_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxBuscarCli.TextChanged
        ListBoxClientes.Items.Clear()
        ListBoxClientes.Items.AddRange(ListBoxClientesIncial.Items)
        Dim countclientes As Integer = ListBoxClientes.Items.Count() - 1

        For i = 0 To countclientes
            'Try

            If (Not ListBoxClientes.Items(i).ToString.ToLower.Contains(TextBoxBuscarCli.Text.ToLower)) Then
                ListBoxClientes.Items.RemoveAt(i)
                countclientes -= 1
                i -= 1
            End If
            If (i = countclientes) Then
                Exit Sub
            End If
            'Catch ex As Exception

            ' End Try
        Next
    End Sub

    Private Sub RealizarVenta(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVentaRealizar.Click
        If ((TextBoxVentasNuevaVendedor.Text = "Haga login para comenzar a vender") Or (TextBoxVentasNuevaPrenda.Text = "Elija prenda desde 'Stock'") Or (TextBoxVentasNuevaCliente.Text = "Elija cliente desde 'Clientes'")) Then
            MsgBox("Rellene los campos obligatorios", MsgBoxStyle.Critical)
        Else
            MsgBox("Venta realizada correctamente", MsgBoxStyle.Information)
        End If
    End Sub


    Private Sub ButtonIrACatalogo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonIrACatalogo.Click
        Try
            Dim a As String = (ListBoxComprasCliente.SelectedItem.ToString)
            For i = 0 To prendas.Length - 1
                If (a.Contains(prendas(i))) Then
                    PictureBoxItem.Image = imgprendas(i)(nextRandom(imgprendas(i).Length - 1, 0))
                    currentDisplayImage = PictureBoxItem.Image
                End If
            Next
            TextBoxStockDetalles.Text = ListBoxComprasCliente.SelectedItem.ToString + vbNewLine + vbNewLine _
             + "Año: " + nextRandom(2012, 1990).ToString + vbNewLine _
             + "Temporada: " + temporadas(nextRandom(temporadas.Length - 1, 0)) + vbNewLine _
             + "Diseñador: " + disenadores(nextRandom(disenadores.Length - 1, 0)) + vbNewLine _
             + vbNewLine _
             + "Precio: " + nextRandom(2000, 100).ToString + "€" + vbNewLine _
             + "Stock: " + nextRandom(50, 0).ToString + " uds" + vbNewLine _
             + "Talla(s): " + nextRandom(35, 30).ToString + "-" + nextRandom(45, 36).ToString + vbNewLine _
             + "Zona: " + rndString(zonas) + vbNewLine _
             + vbNewLine

            TabControl1.SelectedIndex = 0
        Catch ex As Exception

        End Try


    End Sub


    Private Function generarItemAPartirDeFoto(ByVal imagen As Image)
        PictureBoxItem.Image = imagen
        currentDisplayImage = PictureBoxItem.Image



        TextBoxStockDetalles.Text = "Prenda" + " " + rndString(tipos) + " " + surroundByChar(rndString(nombres)) + vbNewLine + vbNewLine _
             + "Año: " + nextRandom(2012, 1990).ToString + vbNewLine _
             + "Temporada: " + temporadas(nextRandom(temporadas.Length - 1, 0)) + vbNewLine _
             + "Diseñador: " + disenadores(nextRandom(disenadores.Length - 1, 0)) + vbNewLine _
             + vbNewLine _
             + "Precio: " + nextRandom(2000, 100).ToString + "€" + vbNewLine _
             + "Stock: " + nextRandom(50, 0).ToString + " uds" + vbNewLine _
             + "Talla(s): " + nextRandom(35, 30).ToString + "-" + nextRandom(45, 36).ToString + vbNewLine _
             + "Zona: " + rndString(zonas) + vbNewLine _
            + vbNewLine


        TabControl1.SelectedIndex = 0
    End Function
    Private Sub PictureBox5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox5.Click
        generarItemAPartirDeFoto(PictureBox5.Image)
    End Sub
    Private Sub PictureBox6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox6.Click
        generarItemAPartirDeFoto(PictureBox6.Image)
    End Sub
    Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click
        generarItemAPartirDeFoto(PictureBox7.Image)
    End Sub
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        generarItemAPartirDeFoto(PictureBox1.Image)
    End Sub
    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        generarItemAPartirDeFoto(PictureBox3.Image)
    End Sub
    Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
        generarItemAPartirDeFoto(PictureBox4.Image)
    End Sub
    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        generarItemAPartirDeFoto(PictureBox2.Image)
    End Sub
    Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
        generarItemAPartirDeFoto(PictureBox8.Image)
    End Sub

    Private Sub BuscarVentas(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVentasBuscar.Click
        ListBoxVentas.Items.Clear()
        ListBoxVentas.Items.AddRange(ListBoxVentasIniciales.Items)
        Dim countventas As Integer = ListBoxVentas.Items.Count() - 1

        For i = 0 To countventas

            'Try
            Dim piezas() As String = ListBoxVentas.Items(i).ToString.Split(separador)
            Dim fecha() As String = piezas(0).Split("/")
            If (CheckBoxVentasFecha.Checked = True) Then
                If ((Not fecha(0).Equals(NumericUpDownVentasAno.ToString())) Or _
                     (Not fecha(1).Equals(NumericUpDownVentasMes.ToString())) Or _
                     (Not fecha(2).Equals(NumericUpDownVentasDia.ToString())) Or _
                     (Not piezas(1).ToLower.Contains(TextBoxVentasCliente.Text.ToLower)) Or _
                     (Not piezas(2).ToLower.Contains(TextBoxVentasVendedor.Text.ToLower)) Or _
                     (Not piezas(3).ToLower.Contains(TextBoxVentasPrenda.Text.ToLower))) Then
                    ListBoxVentas.Items.RemoveAt(i)
                    countventas -= 1
                    i -= 1
                End If
            Else
                If ((Not piezas(1).ToLower.Contains(TextBoxVentasCliente.Text.ToLower)) Or _
                     (Not piezas(2).ToLower.Contains(TextBoxVentasVendedor.Text.ToLower)) Or _
                     (Not piezas(3).ToLower.Contains(TextBoxVentasPrenda.Text.ToLower))) Then
                    ListBoxVentas.Items.RemoveAt(i)
                    countventas -= 1
                    i -= 1
                End If
            End If

            If (i = countventas) Then
                TextBoxVentasResultados.Text = ListBoxVentas.Items.Count.ToString + " Resultados de " + ListBoxVentasIniciales.Items.Count.ToString
                Exit Sub
            End If
            'Catch ex As Exception
            ' End Try
        Next
        TextBoxVentasResultados.Text = ListBoxVentas.Items.Count.ToString + " Resultados (Buscando sobre " + ListBoxVentasIniciales.Items.Count.ToString + " )"

    End Sub


    Private Sub ButtonVentasCliente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVentasCliente.Click
        Try
            Dim piezas() As String = ListBoxVentas.SelectedItem.ToString.Split(separador)
            vieneDeVentas = True
            Call ListBoxClientes_Click(sender, e)
            vieneDeVentas = False
            TabControl1.SelectedIndex = 2
        Catch ex As Exception
            MsgBox("Seleccione un item de la lista", MsgBoxStyle.Critical)
        End Try

    End Sub
    Private Sub ButtonVentasVendedor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVentasVendedor.Click
        Try
            Dim a As Integer = 0
            For i = 0 To ListBoxEmployeesTotal.Items.Count - 1
                If (ListBoxVentas.SelectedItem.ToString.Split("-")(2).ToLower.Contains(ListBoxEmployeesTotal.Items(i).ToString.Split("-")(0).ToLower)) Then
                    a = i
                End If
            Next

            Dim piezas() As String = ListBoxEmployeesTotal.Items(a).ToString.Split(separador)
            piezas(0) = piezas(0).Trim(" ")
            piezas(1) = piezas(1).Trim(" ")
            piezas(2) = piezas(2).Trim(" ")
            piezas(3) = piezas(3).Trim(" ")
            TextBoxEmNombre.Text = piezas(0)
            TextBoxEmPuesto.Text = piezas(1)
            TextBoxEmDepartamento.Text = piezas(2)
            TextBoxEmTienda.Text = piezas(3)
            TextBoxEmAntiguedad.Text = nextRandom(10, 0).ToString + " años"
            TextBoxEmEdad.Text = nextRandom(60, 25).ToString + " años"
            TextBoxEmSueldo.Text = nextRandom(10000, 1500).ToString + "€"
            PictureBoxEmpleado.Image = personas(nextRandom(personas.Length - 1, 0))

            TextBoxEmDetalle.Text = piezas(0) + " ha sido de gran ayuda a la empresa, trabajando de " + piezas(1) + _
            " en el departamento " + piezas(2) + " de la tienda " + piezas(3)
            TabControl1.SelectedIndex = 1
        Catch ex As Exception
            MsgBox("Seleccione un item de la lista", MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub ButtonVentasPrenda_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVentasPrenda.Click
        Try
            Dim a As String = (ListBoxVentas.SelectedItem.ToString.Split("-")(3))
            For i = 0 To prendas.Length - 1
                If (a.Contains(prendas(i))) Then
                    PictureBoxItem.Image = imgprendas(i)(nextRandom(imgprendas(i).Length - 1, 0))
                    currentDisplayImage = PictureBoxItem.Image
                End If
            Next
            TextBoxStockDetalles.Text = ListBoxVentas.SelectedItem.ToString.Split("-")(3) + vbNewLine + vbNewLine _
             + "Año: " + nextRandom(2012, 1990).ToString + vbNewLine _
             + "Temporada: " + temporadas(nextRandom(temporadas.Length - 1, 0)) + vbNewLine _
             + "Diseñador: " + disenadores(nextRandom(disenadores.Length - 1, 0)) + vbNewLine _
             + vbNewLine _
             + "Precio: " + nextRandom(2000, 100).ToString + "€" + vbNewLine _
             + "Stock: " + nextRandom(50, 0).ToString + " uds" + vbNewLine _
             + "Talla(s): " + nextRandom(35, 30).ToString + "-" + nextRandom(45, 36).ToString + vbNewLine _
             + "Zona: " + rndString(zonas) + vbNewLine _
             + vbNewLine

            TabControl1.SelectedIndex = 0
        Catch ex As Exception
            MsgBox("Seleccione un item de la lista", MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub TextBoxNombreCliente_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxNombreCliente.TextChanged
        TextBoxVentasNuevaCliente.Text = TextBoxNombreCliente.Text
        ToolStripStatusLabelClient.Text = "Cliente: " + TextBoxNombreCliente.Text
    End Sub
    Private Sub TextBoxStockDetalles_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxStockDetalles.TextChanged
        TextBoxVentasNuevaPrenda.Text = TextBoxStockDetalles.Text.Split(vbNewLine)(0)
        ToolStripStatusLabelPrenda.Text = "Prenda: " + TextBoxVentasNuevaPrenda.Text
    End Sub


    Dim effectcount As Integer = 0
    Dim effects As Integer = 10
    Dim loadingEstados() As String = {"Verificando ID", "Conectando con DB", "Cargando prendas", "Cargando clientes", "Cargando empleados", "Cargando imágenes", "Generando tienda", "Finalizando", "Finalizando", "Listo!"}
    Private Sub ticktack() Handles Timer1.Tick
        effectcount += 1
        If (effectcount = effects + 1) Then
            Timer1.Stop()
            Exit Sub
        End If
        LabelLoadingStatus.Text = loadingEstados(effectcount - 1)
        ProgressBarLoadingScreen.Value = effectcount * 10
        ToolStripProgressBar1.Value = effectcount * 10
    End Sub
    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim existeEmpleado As Boolean = False
        Dim indice As Integer
        For i = 0 To ListBoxEmployees.Items.Count - 1
            If ((ListBoxEmployees.Items(i).ToString.Split("-")(0).Contains(TextBoxLoginUser.Text)) And (Not (TextBoxLoginUser.Text = "")) And (Not (TextBoxLoginPassword.Text = ""))) Then
                existeEmpleado = True
                indice = i
                ToolStripStatusLabelUser.Text = "Empleado: " + ListBoxEmployees.Items(i).ToString.Split("-")(0)
            End If
        Next
        If (existeEmpleado) Then
            effectcount = 0
            Timer1.Start()
            TextBoxVentasNuevaVendedor.Text = ListBoxEmployees.Items(indice).ToString.Split("-")(0)
        Else
            LabelLoadingStatus.Text = "Error: Usuario o contraseña no válidos"
        End If


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        randomizeShop()
    End Sub


    Private Sub ClickOnSaleZone(ByVal sender As RadioButton, ByVal e As System.EventArgs) Handles E1.Click, E2.Click, E3.Click, E4.Click, E5.Click, T11.Click, T12.Click, T13.Click, T14.Click, T15.Click, T21.Click, T22.Click, T23.Click, T24.Click, T25.Click, T31.Click, T32.Click, T33.Click, T34.Click, T35.Click, T41.Click, T42.Click, T43.Click, T44.Click, T45.Click
        Dim limit As Integer = 100
        If (sender.Tag = "escaparate") Then
            limit = 1000
        End If
        LabelGestionEdad.Text = nextRandom(60, 30).ToString
        LabelGestionGasto.Text = nextRandom(5000, 100).ToString
        LabelGestionVentas.Text = nextRandom(limit, 10).ToString
        LabelGestionEncargado.Text = ListBoxEmployeesTotal.Items(nextRandom(ListBoxEmployeesTotal.Items.Count - 1, 0)).ToString.Split("-")(0)
        ListBoxGestionProductos.Items.Clear()
        ListBoxGestionClientes.Items.Clear()
        For j = 0 To nextRandom(40, 0)
            ListBoxGestionProductos.Items.Add(prendas(nextRandom(prendas.Length - 1, 0)) + " " + tipos(nextRandom(tipos.Length - 1, 0)) + " " + surroundByChar(nombres(nextRandom(nombres.Length - 1, 0))))
        Next
        For j = 0 To nextRandom(40, 0)
            ListBoxGestionClientes.Items.Add(ListBoxClientesIncial.Items(nextRandom(ListBoxClientesIncial.Items.Count - 1, 0)).ToString)
        Next
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Try
            Dim a As String = (ListBoxGestionProductos.SelectedItem.ToString.Split("-")(0))
            For i = 0 To prendas.Length - 1
                If (a.Contains(prendas(i))) Then
                    PictureBoxItem.Image = imgprendas(i)(nextRandom(imgprendas(i).Length - 1, 0))
                    currentDisplayImage = PictureBoxItem.Image
                End If
            Next
            TextBoxStockDetalles.Text = ListBoxGestionProductos.SelectedItem.ToString + vbNewLine + vbNewLine _
             + "Año: " + nextRandom(2012, 1990).ToString + vbNewLine _
             + "Temporada: " + temporadas(nextRandom(temporadas.Length - 1, 0)) + vbNewLine _
             + "Diseñador: " + disenadores(nextRandom(disenadores.Length - 1, 0)) + vbNewLine _
             + vbNewLine _
             + "Precio: " + nextRandom(2000, 100).ToString + "€" + vbNewLine _
             + "Stock: " + nextRandom(50, 0).ToString + " uds" + vbNewLine _
             + "Talla(s): " + nextRandom(35, 30).ToString + "-" + nextRandom(45, 36).ToString + vbNewLine _
             + "Zona: " + rndString(zonas) + vbNewLine _
             + vbNewLine

            TabControl1.SelectedIndex = 0
        Catch ex As Exception
            MsgBox("Seleccione un item", MsgBoxStyle.Critical)
        End Try
    End Sub
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Try
            Dim piezas() As String = ListBoxGestionClientes.SelectedItem.ToString.Split(separador)
            vieneDeClientes = True
            Call ListBoxClientes_Click(sender, e)
            vieneDeClientes = False
            TabControl1.SelectedIndex = 2
        Catch ex As Exception
            MsgBox("Seleccione un item", MsgBoxStyle.Critical)
        End Try
    End Sub




    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        randomizeEmployees()
        randomizeClients()
        randomizeSales()
        randomizeShop()
        TextBoxVentasFactura.Text = nextRandom(999999, 100000).ToString
        Dim h As String = DateValue(Now)
        Dim j() As String = h.Split("/")
        NumericUpDownVentasDia.Value = j(0)
        NumericUpDownVentasDia2.Value = j(0)
        NumericUpDownVentasAno.Value = j(2)
        NumericUpDownVentasAno2.Value = j(2)
        NumericUpDownVentasMes.Value = j(1)
        NumericUpDownVentasMes2.Value = j(1)
        'TabControl1.SelectedIndex = 5

    End Sub

    Private Sub ButtonAnadirNuevoProducto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAnadirNuevoProducto.Click
        NewProduct.Show()
    End Sub

    'funciones de admin para empleado
    Private Sub ButtonEditarEm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEditarEm.Click
        If TextBoxEmNombre.Text = "" Then
            MsgBox("No hay empleado que editar", MsgBoxStyle.Information)
            Exit Sub
        End If

        If TextBoxEmAntiguedad.ReadOnly = False Then
            TextBoxEmAntiguedad.ReadOnly = True
            TextBoxEmDepartamento.ReadOnly = True
            TextBoxEmDetalle.ReadOnly = True
            TextBoxEmEdad.ReadOnly = True
            TextBoxEmNombre.ReadOnly = True
            TextBoxEmPuesto.ReadOnly = True
            TextBoxEmTienda.ReadOnly = True
            TextBoxEmSueldo.ReadOnly = True
            ButtonEditarEm.Text = "Editar Empleado"
            MsgBox("Edición correcta", MsgBoxStyle.Information)
        Else
            ButtonEditarEm.Text = "Guardar cambios"
            TextBoxEmAntiguedad.ReadOnly = False
            TextBoxEmDepartamento.ReadOnly = False
            TextBoxEmDetalle.ReadOnly = False
            TextBoxEmEdad.ReadOnly = False
            TextBoxEmNombre.ReadOnly = False
            TextBoxEmPuesto.ReadOnly = False
            TextBoxEmTienda.ReadOnly = False
            TextBoxEmSueldo.ReadOnly = False
        End If
    End Sub
    Private Sub ButtonAnadirEm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAnadirEm.Click
        NewEmployee.Show()
    End Sub
    Private Sub ButtonDarDeBajaEm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDarDeBajaEm.Click
        Try
            Dim a As String = ListBoxEmployees.SelectedItem.ToString
            For i = 0 To ListBoxEmployeesTotal.Items.Count - 1
                If (ListBoxEmployeesTotal.Items(i).ToString.Contains(ListBoxEmployees.SelectedItem.ToString)) Then
                    ListBoxEmployeesTotal.Items.RemoveAt(i)
                    MsgBox("Dado de baja exitosamente")
                    ListBoxEmployees.Items.Clear()
                    ListBoxEmployees.Items.AddRange(ListBoxEmployeesTotal.Items)
                    Exit Sub
                End If
            Next
        Catch ex As Exception
            MsgBox("Seleccione un empleado")
        End Try
    End Sub

    'funciones de admin para cliente
    Private Sub ButtonClienteEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClienteEdit.Click
        If TextBoxNombreCliente.Text = "" Then
            MsgBox("No hay cliente que editar", MsgBoxStyle.Information)
            Exit Sub
        End If

        If (TextBoxClienteEmail.ReadOnly) Then
            TextBoxClienteEmail.ReadOnly = False
            TextBoxClienteTelefono.ReadOnly = False
            TextBoxTallaCliente.ReadOnly = False
        Else
            TextBoxClienteEmail.ReadOnly = True
            TextBoxClienteTelefono.ReadOnly = True
            TextBoxTallaCliente.ReadOnly = True
            MsgBox("Edición correcta", MsgBoxStyle.Information)
        End If
    End Sub
    Private Sub ButtonClienteAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClienteAdd.Click
        NewClient.Show()
    End Sub
    Private Sub ButtonClienteBaja_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClienteBaja.Click
        Try
            Dim a As String = ListBoxClientes.SelectedItem.ToString
            For i = 0 To ListBoxClientesIncial.Items.Count - 1
                If (ListBoxClientesIncial.Items(i).ToString.Contains(ListBoxClientes.SelectedItem.ToString)) Then
                    ListBoxClientesIncial.Items.RemoveAt(i)
                    MsgBox("Dado de baja exitosamente")
                    ListBoxClientes.Items.Clear()
                    ListBoxClientes.Items.AddRange(ListBoxClientesIncial.Items)
                    Exit Sub
                End If
            Next
        Catch ex As Exception
            MsgBox("Seleccione un cliente")
        End Try
    End Sub

    Private Sub KeyDownOnSaleZone(ByVal sender As RadioButton, ByVal e As System.Windows.Forms.KeyEventArgs) Handles E1.KeyDown, E2.KeyDown, E3.KeyDown, E4.KeyDown, E5.KeyDown, T11.KeyDown, T12.KeyDown, T13.KeyDown, T14.KeyDown, T15.KeyDown, T21.KeyDown, T22.KeyDown, T23.KeyDown, T24.KeyDown, T25.KeyDown, T31.KeyDown, T32.KeyDown, T33.KeyDown, T34.KeyDown, T35.KeyDown, T41.KeyDown, T42.KeyDown, T43.KeyDown, T44.KeyDown, T45.KeyDown
        If (sender.Tag = "escaparate" And P1.Checked) Then
            sender.Image = P1.Image
            Exit Sub
        ElseIf P2.Checked Then
            sender.Image = P2.Image
            Exit Sub
        ElseIf sender.Tag = "escaparate" Then
            MsgBox("No es posible este elemento para el seleccionado", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If (P3.Checked) Then
            sender.Image = P3.Image
        ElseIf P4.Checked Then
            sender.Image = P4.Image
        ElseIf P5.Checked Then
            sender.Image = P5.Image
        ElseIf P6.Checked Then
            sender.Image = P6.Image
        Else
            MsgBox("No es posible este elemento para el seleccionado", MsgBoxStyle.Critical)
        End If
    End Sub


    Private Sub ButtonTiendaModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTiendaModify.Click
        MsgBox("Nueva disposición de la tienda guardada correctamente", MsgBoxStyle.Information)
    End Sub

    Private Sub ComboBoxTiendas_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxTiendas.SelectedIndexChanged
        TextBoxTiendaDetalle.Text = "Está usted en la tienda: " + ComboBoxTiendas.SelectedItem.ToString + vbNewLine + _
        "La tienda lleva abierta desde 1980 " + vbNewLine + _
        "Sus productos son concidos en todo madrid"
        ToolStripStatusLabelTienda.Text = "Tienda: " + ComboBoxTiendas.SelectedItem.ToString
    End Sub

    Private Sub ButtonTiendaCrear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTiendaCrear.Click
        NewShop.Show()
    End Sub



    Private Sub CheckBoxCliente_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxCliente.CheckedChanged
        If CheckBoxCliente.Checked Then
            TextBoxVentasNuevaCliente.Text = "Elija cliente desde 'Clientes'"
        Else
            TextBoxVentasNuevaCliente.Text = ""
        End If
    End Sub

End Class